#include <sys/types.h>
#include <sys/socket.h> 
#include <netinet/in.h>
#include <string.h>
#include <stdlib.h>

/**
 * @author Sajal Jain
 * Demo Commit 3
 */



int main()
{
	int socket_desc;
	socket_desc=socket(AF_INET,SOCK_STREAM,0);
  	if (socket_desc==-1)
    	perror("Create socket");
	struct sockaddr_in address;
	address.sin_family = AF_INET;
  	address.sin_addr.s_addr = INADDR_ANY;
	address.sin_port = htons(7000);
	bind(socket_desc,(struct sockaddr *)&address,sizeof(address));
	listen(socket_desc,3);
	
	int addrlen = sizeof(struct sockaddr_in);
  	int new_socket = accept(socket_desc, (struct sockaddr *)&address, &addrlen);
  	if (new_socket<0)
    	perror("Accept connection");

	char *message="Hi, my name is Sajal Jain\n\r";
	send(new_socket,message,strlen(message),0);

	int bufsize=1024;        /* a 1K buffer */
	char *buffer=malloc(bufsize);
	recv(new_socket,buffer,bufsize,0);

	close(new_socket);

	return 0;
}
